import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from unittest import TestCase
class TestRegister(TestCase):
    def testRegister1(self):
        username = 'wangwu'
        password = '123456'
        expect = '立即登录'
        driver = webdriver.Chrome()
        driver.get('http://localhost:90')
        driver.maximize_window()
        driver.find_element(By.XPATH, '/html/body/div/div/div/div[2]/a').click()
        driver.find_element(By.ID, 'username').send_keys(username)
        driver.find_element(By.ID, 'password').send_keys(password)
        driver.find_element(By.ID, 'repassword').send_keys(password)
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        time.sleep(3)
        result = driver.find_element(By.XPATH,'//*[@id="login_btn"]').text
        if result!=expect:
            driver.save_screenshot('wangwu-----123456')
        self.assertEqual(expect,result)
        driver.close()
    def testRegister2(self):
        username='wangwu1'
        password='123456'
        expect='用户已存在'
        driver=webdriver.Chrome()
        driver.get('http://localhost:90')
        driver.maximize_window()
        driver.find_element(By.XPATH,'/html/body/div/div/div/div[2]/a').click()
        driver.find_element(By.ID, 'username').send_keys(username)
        driver.find_element(By.ID, 'password').send_keys(password)
        driver.find_element(By.ID, 'repassword').send_keys(password)
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        time.sleep(3)
        result=driver.find_element(By.XPATH,'/html/body/div/div/div/form/div[1]/span[1]').text
        if result!=expect:
            driver.save_screenshot('wangwu1----123456.png')
        self.assertEqual(expect,result)
        driver.close()
    def testRegister3(self):
        username='wangwu'
        password='123456'
        w_password='1234567'
        expect='已有账号？去登录'
        driver=webdriver.Chrome()
        driver.get("http://localhost:90")
        driver.maximize_window()
        driver.find_element(By.XPATH, '/html/body/div/div/div/div[2]/a').click()
        driver.find_element(By.ID, 'username').send_keys(username)
        driver.find_element(By.ID, 'password').send_keys(password)
        time.sleep(3)
        driver.find_element(By.ID, 'repassword').send_keys(w_password)
        time.sleep(3)
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        time.sleep(3)
        result=driver.find_element(By.XPATH,'/html/body/div/div/div/div[2]/a').text
        if result != expect:
            driver.save_screenshot('wangwu-----1234567.png')
        self.assertEqual(expect,result)
        driver.close()
